package com.rj.bd.reservation.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rj.bd.manufacturer.entity.Manufacturer;
import com.rj.bd.person.entity.Person;
import com.rj.bd.reservation.entity.Reservation;
import com.rj.bd.type.entity.Type;
import com.rj.bd.vaccine.entity.Vaccine;

public interface ReservationMapper extends BaseMapper<Reservation>{
	@Select("select * from reservation r join person p on r.pId=p.pId ${ew.customSqlSegment}")
	@Results(value={
			@Result(javaType=Manufacturer.class,column="mId",property="manufacturer",
					one=@One(select="com.rj.bd.manufacturer.dao.ManufacturerMapper.selectById")),
			
			@Result(javaType=Type.class,column="typeId",property="type",
					one=@One(select="com.rj.bd.type.dao.TypeMapper.selectById")),
			
			@Result(javaType=Vaccine.class,column="vId",property="vaccine",
				one=@One(select="com.rj.bd.vaccine.dao.VaccineMapper.selectById")),
			
			@Result(javaType=Person.class,column="pId",property="person",
			one=@One(select="com.rj.bd.person.dao.PersonMapper.selectById")),
			
			@Result(javaType=String.class,column="mId",property="mId"),
			@Result(javaType=String.class,column="typeId",property="typeId"),
			@Result(javaType=String.class,column="vId",property="vId"),
			@Result(javaType=String.class,column="pId",property="pId")
	})
	IPage<Reservation> selectPage(IPage<Reservation> page, @Param("ew") Wrapper<Reservation> queryWrapper);
	
	
	
	
	@Select("select *from reservation where rid=#{rId}")
    List<Reservation> selectListById(String rId);
 
	@Insert("insert into reservation (rId,pId,irritability,health,date,state,vname,total,single,mId,vId,typeId,location,jiluren) values (#{rId},#{pId},#{irritability},#{health},#{date},#{state},#{vname},#{total},#{single},#{mId},#{vId},#{typeId},#{location},#{jiluren})")
	public void save(Reservation reservation);
	
	@Delete("delete from reservation where rId=#{rId}")
	public void delete(String rId);



	@Update("update reservation set pId=#{pId},irritability=#{irritability},health=#{health},date=#{date},state=#{state},vname=#{vname},total=#{total},single=#{single},mId=#{mId},vId=#{vId},typeId=#{typeId},location=#{location},jiluren=#{jiluren} where rId=#{rId}")
	public void edit(Reservation reservation);
}
